package com.yj.daily.jvm;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Demo02 {
    private static List<User> users = new ArrayList<>(); // tom

    static {
        users = Arrays.asList( new User(1, "bob@example.com", "password", "Bob"), // bob
                new User(2, "alice@example.com", "password", "Alice"), // alice
                new User(3, "tom@example.com", "password", "Tom"));
    }


    public static void main(String[] args) throws Exception {


        User yijian = new User(users.stream().mapToLong(value -> {
            return (long) value.getId();
        }).max().getAsLong(), "123", "123", "yijian");
        System.out.println(yijian);

        User user1 = users.stream().filter(user -> {
            return user.getId() == 1;
        }).findFirst().orElseThrow(Exception::new);
        System.out.println(user1);


    }
}

class User{

    private long id;
    private String email;
    private String password;
    private String name;


    public User(long id, String email, String password, String name) {
        this.id = id;
        this.email = email;
        this.password = password;
        this.name = name;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", email='" + email + '\'' +
                ", password='" + password + '\'' +
                ", name='" + name + '\'' +
                '}';
    }
}
